{- Latency.inc.orc -- Orc program Latency.inc
 - 
 - $Id$
 - 
 - Created by akattepu on 07-Aug-2012 17:05:11
 -}

def bestQoS(comparer, publisher) = head(sortBy(comparer, publisher))
val curTime = Rclock()
def LatencyIncrement(sitex) = (sitex,curTime.time()) >(sitex,d)> (sitex,curTime.time()-d) 

type Millisecond = Number
def Millisecond() = signal
type Second = Number
def Second() = signal 
 
-- Types and Definitions for Response Time
type ResponseTime = Number
def class ResponseTime(unit) =
  def QoS(String) :: Number
  def QoS(sitex) = 
   signal >> LatencyIncrement(sitex) >(_,q)> (Ift(unit = Millisecond) >> q | Ift(unit = Second) >> q/1000)
  
  def QoSOplus(Number,Number) :: Number
  def QoSOplus(rt1,rt2) = rt1+rt2
  
  def QoSCompare(Number,Number) :: Number
  def QoSCompare(rt1,rt2) = rt1 <= rt2
  
  def QoSCompete(Number,Number) :: Number
  def QoSCompete(rt1,rt2) = bestQoS(QoSCompare,[rt1,rt2])
  
  def QoSVee(Number,Number) :: Number
  def QoSVee(rt1,rt2) = max(rt1,rt2)
  stop